import {
  getPersonalizedApi,
  getPlayListDetailApi,
  getSongListCommentApi,
  likeCommentApi,
} from '@renderer/api'
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { commentType, PersonalizedType, songListCommentType, songListDetailType } from './type'
import { songsType } from '@renderer/store/type'
import { likeCommentType } from '@renderer/types'

export const useSongListStore = defineStore('SongListStore', () => {
  // 推荐歌单数据
  const RecSongList = ref([] as PersonalizedType[])
  // 歌单详情数据
  const songListDetail = ref({} as songListDetailType)
  // 歌单歌曲数据
  const songsList = ref([] as songsType[])
  // 歌单评论数据
  const songListComment = ref([] as commentType[])

  //获取推荐歌单
  const getPersonalized = async () => {
    let res: any = await getPersonalizedApi()
    RecSongList.value = res.result
  }
  // 获取歌单详情
  const getSongListDetail = async (id: number) => {
    let res: any = await getPlayListDetailApi(id)
    songListDetail.value = res.playlist
    songsList.value = res.playlist.tracks
  }
  // 获取歌单评论
  const getSongListComment = async (id: number) => {
    let res: songListCommentType = await getSongListCommentApi(id)
    songListComment.value = res.comments
  }
  // 点赞评论
  const getLikeComment = async (likeComment: likeCommentType) => {
    await likeCommentApi(likeComment)
  }

  return {
    RecSongList,
    songListDetail,
    songsList,
    songListComment,
    getPersonalized,
    getSongListDetail,
    getSongListComment,
    getLikeComment,
  }
})
